package utils

const (
	Success                = 200
	ServerError            = 10101
	TooManyRequests        = 10102
	ParamBindError         = 10103
	AuthorizationError     = 10104
	UrlSignError           = 10105
	CacheSetError          = 10106
	CacheGetError          = 10107
	CacheDelError          = 10108
	CacheNotExist          = 10109
	ResubmitError          = 10110
	HashIdsEncodeError     = 10111
	HashIdsDecodeError     = 10112
	RBACError              = 10113
	RedisConnectError      = 10114
	MySQLConnectError      = 10115
	WriteConfigError       = 10116
	SendEmailError         = 10117
	MySQLExecError         = 10118
	GoVersionError         = 10119
	SocketConnectError     = 10120
	SocketSendError        = 10121
	DeleteError            = 10122
	UpdateError            = 10123
	InsertError            = 10124
	GetError               = 10125
	GetCountError          = 10126
	GetTokenError          = 10127
	GetUserPrivateKeyError = 10128
	GetWithdrawError       = 10129

	AuthorizedCreateError    = 20101
	AuthorizedListError      = 20102
	AuthorizedDeleteError    = 20103
	AuthorizedUpdateError    = 20104
	AuthorizedDetailError    = 20105
	AuthorizedCreateAPIError = 20106
	AuthorizedListAPIError   = 20107
	AuthorizedDeleteAPIError = 20108
	GetProductListError      = 20702
	ExchangeError            = 21102

	MongodbNoData         = 30101
	MongodbCountError     = 30102
	MongodbFindDataError  = 30103
	MongodbAggregateError = 30104
	MongodbDataIsExist    = 30105

	ParseDataError               = 40101 //解析data
	CallBackError                = 40102
	CodeError                    = 40103
	FeeAddressNotPrivateKey      = 40104
	WithdrawAddressNotPrivateKey = 40105
	EmailCodeError               = 40106
	UserNotExist                 = 40107
	CodeExpired                  = 40108
	GasFeeError                  = 40109
	AbiParseError                = 40110 //abi解析error
	SendTransactionError         = 40111
	CallbackFailed               = 40112
	DuplicateCollection          = 40113
	ParamNotNull                 = 40114
	UserNameOrPasswordError      = 40115
	UserStatusStop               = 40116
	GenerateTokenError           = 40117
	PageParamInvalid             = 40118
	MissChainName                = 40119
	MissChainId                  = 40120
	BodyNotEmpty                 = 40121
	NonceNotEmpty                = 40122
	SignNotEmpty                 = 40123
	TimeStampNotEmpty            = 40124
	BodyParseError               = 40125
	UserNotMemberOrStop          = 40126
	MainCoinTypeInvalid          = 40127
	ConnectRpcUrlError           = 40128
	SignError                    = 40129
	GeneratePrivateError         = 40130
	ChainIdNotMatch              = 40131
	CreateWalletError            = 40132
	TransferError                = 40133
	PrivateKeyParseError         = 40134
	EthToWeiError                = 40135
	GenerateAddressError         = 40136
	AddressFormatError           = 40137
	RepeatedWithdraw             = 40138
)

func Text(code int, language string) string {

	switch language {
	case "en-us":
		return enUSText[code]
	case "zh-ch":
		return zhCnText[code]
	case "ja-jp":
		return jaJpText[code]
	case "ko-kr":
		return koKrText[code]
	case "zh-tw":
		return zhTwText[code]

	}
	return zhTwText[code]
}

type Response struct {
	Code    int         `json:"code"` // 状态码
	Data    interface{} `json:"data"` // 响应数据
	Message string      `json:"msg"`  // 消息或描述
}

func GetResponse(err error, code int, data interface{}, language string) Response {
	var message string
	if code != 200 {
		if err != nil {
			message = Text(code, language) + ": " + err.Error() // 使用错误的描述作为消息
		} else {
			message = Text(code, language)
		}
	} else {
		message = Text(code, language) // 成功时的默认消息
	}

	return Response{
		Code:    code,
		Data:    data,
		Message: message,
	}
}
